﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SoundEdge.Common;
using SoundEdge.Media.Project;
using SoundEdge.Media.Filter;

namespace SoundEdge.WinControls
{
    public partial class WaveFilterLibrary : UserControl
    {
        public ISoundEdgeProject Project { get; set; }

        public WaveFilterLibrary()
        {
            InitializeComponent();
        }

        private void WaveFilterLibrary_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ListViewItem)))
            {
                ListViewItem sourceItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
                if (sourceItem.Tag == null || sourceItem.Tag.GetType().GetInterface("SoundEdge.Common.IWaveFilter") == null)
                {
                    e.Effect = DragDropEffects.None;
                    return;
                }
                else
                {
                    e.Effect = DragDropEffects.Move;
                }
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void WaveFilterLibrary_DragDrop(object sender, DragEventArgs e)
        {
            ListViewItem sourceItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));

            ListViewItem item = sourceItem.Clone() as ListViewItem;
            IWaveFilter filter = item.Tag as IWaveFilter;
            if (filter == null)
            {
                throw new ArgumentNullException("The item does not have an associated filter.");
            }

            this.listView.Items.Add(item);
            AddFilter(item.Tag as IWaveFilter);
            //AddSelected(sourceNode, false);
            //RefreshSelectedObjectsDataFromProject();
        }

        private void AddFilter(IWaveFilter filter)
        {
            if (Project == null)
            {
                return;
            }

            Project.Filters.Add(filter);
        }

        private void listView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
